
package com.admissions.network;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

/**
 * @author Bkav-DangNVb
 */
public class HttpHelper {

    private static final String TAG = "HttpHelper";

    public static String getJsonData(String url) {
        StringBuilder builder = new StringBuilder();
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            InputStream is = httpEntity.getContent();

            BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
            String line = "";
            while ((line = buffer.readLine()) != null) {
                builder.append(line);
            }
        } catch (Exception e) {
            Log.e(TAG, "Failed to download json: " + e.toString());
            return null;
        }
        return builder.toString();
    }
}
